//
//  AddMeterParamCell.swift
//  Employee
//
//  Created by tancheng on 2018/6/21.
//  Copyright © 2018年 remotevillage. All rights reserved.
//

import UIKit

//单行文本、选择
class AddMeterTextParamCell: UITableViewCell {

    static let reuseIdentifier = "AddMeterTextParamCell"
    
    var paramModel: AddMeterModel? {
        didSet {
            updateData()
        }
    }
    
    lazy var subContentView:UIView = {
        let vi = UIView()
        vi.backgroundColor = UIColor.white
        vi.layer.cornerRadius = 2
        vi.layer.masksToBounds = true
        return vi
    }()
    
    private lazy var nameLab: UILabel = {
        let lab = UILabel()
        lab.font = UIFont.systemFont(ofSize: 16)
        lab.textColor = GlobalConfig.TextDeepColor
        lab.textAlignment = .left
        return lab
    }()
    
    private lazy var contentTf: UITextField = {
        let tf = UITextField()
        tf.textColor = UIColor.black
        tf.font = UIFont.systemFont(ofSize: 16)
        tf.borderStyle = .none
        tf.textAlignment = .right
        tf.isUserInteractionEnabled = false
        return tf
    }()
    
    private lazy var rightArrow: UIImageView = {
        let img = UIImageView(image: UIImage(named: "下一级符号"))
        return img
    }()
    
    
    //
    private func layoutUI() {
        
        contentView.backgroundColor = GlobalConfig.pageColor
        
        contentView.addSubview(subContentView)
        subContentView.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(0)
            make.left.equalToSuperview().offset(10)
            make.right.equalToSuperview().offset(-10)
            make.bottom.equalToSuperview().offset(-10)
        }
        
        subContentView.addSubview(nameLab)
        nameLab.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.left.equalToSuperview().offset(20)
        }
        
        subContentView.addSubview(rightArrow)
        rightArrow.snp.makeConstraints { (make) in
            make.right.equalToSuperview().offset(-20)
            make.centerY.equalToSuperview()
        }
        
        subContentView.addSubview(contentTf)
        contentTf.snp.makeConstraints { (make) in
            make.top.bottom.equalToSuperview()
            make.right.equalToSuperview().offset(-52)
            make.width.equalTo(166)
        }
        
    }
    
    //业务配置
    func updateData() {
        
        nameLab.text = paramModel?.name.first
        
        contentTf.text = paramModel?.inputText.first
        
        if let tx = paramModel?.inputText.first {
            contentTf.text = tx.isEmpty ? paramModel?.placeHolder.first : tx
            contentTf.textColor = tx.isEmpty ? UIColor.hex("#323C49", alpha: 0.4) : UIColor.hex("#323C49")
        }
        
    }
    
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        layoutUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
